package com.huaxin.device.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.huaxin.device.dto.ResponseResult;
import com.huaxin.device.dto.request.DeviceDataCollectionWideAddDTO;
import com.huaxin.device.dto.request.DeviceDataCollectionWideQueryByDataTypePageListReqDTO;
import com.huaxin.device.models.DeviceDataCollectionWide;
import com.huaxin.device.service.DeviceDataCollectionWideService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Tag(name = "采集数据")
@RestController
@RequiredArgsConstructor
@RequestMapping("/v1/device/deviceDataCollectionWide")
public class DeviceDataCollectionWideController {
    private final DeviceDataCollectionWideService deviceDataCollectionWideService;

    //添加设备数据
    @PostMapping("/addDeviceData")
    @Operation(summary = "查询设备数据", description = "查询设备数据")
    public boolean addDeviceData(@RequestBody List<DeviceDataCollectionWideAddDTO> deviceDataCollectionWide, String stationNumber) {
        return deviceDataCollectionWideService.addDeviceData(deviceDataCollectionWide, stationNumber);
    }

    //查询设备数据
    @PostMapping("/queryDeviceData")
    @Operation(summary = "查询设备数据", description = "查询设备数据")
    public ResponseResult<Page<DeviceDataCollectionWide>> queryDeviceData(@Parameter(description = "页码", required = true) @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
                                                                          @Parameter(description = "页大小", required = true) @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                                                                          @Parameter(description = "设备ID", required = true) @RequestParam(value = "deviceId", required = false) String deviceId,
                                                                          @Parameter(description = "站点编号", required = true) @RequestParam(value = "stationNumber", required = false) String stationNumber) {
        return ResponseResult.ok(deviceDataCollectionWideService.queryDeviceData(pageNum, pageSize, deviceId, stationNumber));
    }

    @PostMapping("/queryDeviceDataByDataType")
    @Operation(summary = "查询设备的指定数据", description = "查询设备的指定数据")
    public ResponseResult<IPage<Map<String, Object>>> queryDeviceDataByDataType(@RequestBody @Valid DeviceDataCollectionWideQueryByDataTypePageListReqDTO in) {
        return deviceDataCollectionWideService.queryDeviceDataByDataType(in);
    }
}
